package com.io.IO;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class TimeServer {

	public static void main(String[] args) {
		int port = 8080;
		if(args != null && args.length>0) {
			try{
				port = Integer.valueOf(args[0]);
			}catch (Exception e) {

			}
		}
		ServerSocket server =null;
		try {
			server = new ServerSocket(port);
			System.err.println("The time server is start in port : "+port);
			Socket socket =null;
			while(true) {
				socket = server.accept();
				new Thread(new TimeServerHandler(socket)).start();
			}
		} catch (Exception e) {
			// TODO: handle exception
		}finally {

			try {
				if(server !=null) {
					System.out.println("The time server close");
					server.close();
					server = null;
				}
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

	}

}

